// Define a protobuf message type. type MyMessage struct { Field1 string `protobuf:"bytes,1,opt,name=field1" json:"field1,omitempty"` Field2 int32 `protobuf:"varint,2,opt,name=field2" json:"field2,omitempty"` } // Create a Value with a protobuf-encoded MyMessage and a timestamp. myVal := &roachpb.Value{ RawBytes: proto.Marshal(&MyMessage{Field1: "hello", Field2: 42}), Timestamp: hlc.Timestamp{WallTime: time.Now().UnixNano()}, } // Use GetProto to decode the value into a MyMessage struct. myProtoVal, err := myVal.GetProto(&MyMessage{}) if err != nil { log.Fatalf("Error decoding value: %v", err) } fmt.Printf("Field1: %v, Field2: %v", myProtoVal.(*MyMessage).Field1, myProtoVal.(*MyMessage).Field2)
// Create a Value with a random byte slice and a timestamp. myVal := &roachpb.Value{ RawBytes: []byte{0x01, 0x02, 0x03, 0x04}, Timestamp: hlc.Timestamp{WallTime: time.Now().UnixNano()}, } // Use GetProto with an empty message type to decode the value into a raw byte slice. myRawVal, err := myVal.GetProto(&struct{}{}) if err != nil { log.Fatalf("Error decoding value: %v", err) } fmt.Printf("Raw value: %v", myRawVal.([]byte))In this example, `GetProto` is used to decode a `roachpb.Value` with a random byte slice. An empty message type is used to decode the value into a raw byte slice, which is then accessed and printed. Overall, `github.com.cockroachdb.cockroach.roachpb` is a package library for CockroachDB's internal protobuf message types.