Esempio n. 1
0
func _Communique_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
	m := msg.(*Communique)
	// union
	switch x := m.Union.(type) {
	case *Communique_Number:
		b.EncodeVarint(5<<3 | proto.WireVarint)
		b.EncodeVarint(uint64(x.Number))
	case *Communique_Name:
		b.EncodeVarint(6<<3 | proto.WireBytes)
		b.EncodeStringBytes(x.Name)
	case *Communique_Data:
		b.EncodeVarint(7<<3 | proto.WireBytes)
		b.EncodeRawBytes(x.Data)
	case *Communique_TempC:
		b.EncodeVarint(8<<3 | proto.WireFixed64)
		b.EncodeFixed64(math.Float64bits(x.TempC))
	case *Communique_Height:
		b.EncodeVarint(9<<3 | proto.WireFixed32)
		b.EncodeFixed32(uint64(math.Float32bits(x.Height)))
	case *Communique_Today:
		b.EncodeVarint(10<<3 | proto.WireVarint)
		b.EncodeVarint(uint64(x.Today))
	case *Communique_Maybe:
		t := uint64(0)
		if x.Maybe {
			t = 1
		}
		b.EncodeVarint(11<<3 | proto.WireVarint)
		b.EncodeVarint(t)
	case *Communique_Delta_:
		b.EncodeVarint(12<<3 | proto.WireVarint)
		b.EncodeZigzag32(uint64(x.Delta))
	case *Communique_Msg:
		b.EncodeVarint(13<<3 | proto.WireBytes)
		if err := b.EncodeMessage(x.Msg); err != nil {
			return err
		}
	case *Communique_Somegroup:
		b.EncodeVarint(14<<3 | proto.WireStartGroup)
		if err := b.Marshal(x.Somegroup); err != nil {
			return err
		}
		b.EncodeVarint(14<<3 | proto.WireEndGroup)
	case nil:
	default:
		return fmt.Errorf("Communique.Union has unexpected type %T", x)
	}
	return nil
}