Skip to content

Commit

Permalink
fix(jce): replacment not equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Dec 9, 2021
1 parent b041fc2 commit f1d2259
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 109 deletions.
12 changes: 6 additions & 6 deletions binary/jce/gen/structs_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func writeObject(w io.Writer, v reflect.Value, tag byte, name string) {
}
switch k {
case reflect.Uint8, reflect.Int8:
w.Write([]byte(fmt.Sprintf("\tw.WriteByte(byte(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteByte(pkt.%s, %d)\n", name, tag)))
case reflect.Uint16, reflect.Int16:
w.Write([]byte(fmt.Sprintf("\tw.WriteInt16(int16(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteInt16(pkt.%s, %d)\n", name, tag)))
case reflect.Uint32, reflect.Int32:
w.Write([]byte(fmt.Sprintf("\tw.WriteInt32(int32(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteInt32(pkt.%s, %d)\n", name, tag)))
case reflect.Uint64, reflect.Int64:
w.Write([]byte(fmt.Sprintf("\tw.WriteInt64(int64(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteInt64(pkt.%s, %d)\n", name, tag)))
case reflect.String:
w.Write([]byte(fmt.Sprintf("\tw.WriteString(pkt.%s, %d)\n", name, tag)))
default:
Expand Down Expand Up @@ -148,9 +148,9 @@ func writeJceStructRaw(w io.Writer, s interface{}) {
}

func WriteJceStruct(w io.Writer, s jce.IJceStruct) {
w.Write([]byte(fmt.Sprintf("func (pkt %s) ToBytes() []byte {\n", strings.ReplaceAll(reflect.TypeOf(s).String(), "jce.", ""))))
w.Write([]byte(fmt.Sprintf("\nfunc (pkt %s) ToBytes() []byte {\n", strings.ReplaceAll(reflect.TypeOf(s).String(), "jce.", ""))))
w.Write([]byte("\tw := NewJceWriter()\n"))
writeJceStructRaw(w, s)
w.Write([]byte("\treturn w.Bytes()\n"))
w.Write([]byte("}\n\n"))
w.Write([]byte("}\n"))
}
188 changes: 94 additions & 94 deletions binary/jce/structs_tobytes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions binary/jce/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewJceWriter() *JceWriter {

func (w *JceWriter) writeHead(t, tag byte) {
if tag < 0xF {
w.buf.WriteByte(byte(tag<<4) | t)
w.buf.WriteByte(tag<<4 | t)
} else {
w.buf.WriteByte(0xF0 | t)
w.buf.WriteByte(tag)
Expand Down Expand Up @@ -145,7 +145,7 @@ func (w *JceWriter) WriteBytes(l []byte, tag byte) *JceWriter {
func (w *JceWriter) WriteInt64Slice(l []int64, tag byte) {
w.writeHead(9, tag)
if len(l) == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(len(l)), 0)
Expand All @@ -157,7 +157,7 @@ func (w *JceWriter) WriteInt64Slice(l []int64, tag byte) {
func (w *JceWriter) WriteBytesSlice(l [][]byte, tag byte) {
w.writeHead(9, tag)
if len(l) == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(len(l)), 0)
Expand All @@ -180,7 +180,7 @@ func (w *JceWriter) writeSlice(slice reflect.Value, tag byte) {
}
w.writeHead(9, tag)
if slice.Len() == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(slice.Len()), 0)
Expand All @@ -193,7 +193,7 @@ func (w *JceWriter) writeSlice(slice reflect.Value, tag byte) {
func (w *JceWriter) WriteJceStructSlice(l []IJceStruct, tag byte) {
w.writeHead(9, tag)
if len(l) == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(len(l)), 0)
Expand All @@ -213,7 +213,7 @@ func (w *JceWriter) WriteMap(m interface{}, tag byte) {
func (w *JceWriter) writeMap(m reflect.Value, tag byte) {
if m.IsNil() {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
if m.Kind() != reflect.Map {
Expand All @@ -231,7 +231,7 @@ func (w *JceWriter) writeMap(m reflect.Value, tag byte) {
func (w *JceWriter) writeMapStrStr(m map[string]string, tag byte) {
if m == nil {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.writeHead(8, tag)
Expand All @@ -245,7 +245,7 @@ func (w *JceWriter) writeMapStrStr(m map[string]string, tag byte) {
func (w *JceWriter) writeMapStrBytes(m map[string][]byte, tag byte) {
if m == nil {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.writeHead(8, tag)
Expand All @@ -259,7 +259,7 @@ func (w *JceWriter) writeMapStrBytes(m map[string][]byte, tag byte) {
func (w *JceWriter) writeMapStrMapStrBytes(m map[string]map[string][]byte, tag byte) {
if m == nil {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.writeHead(8, tag)
Expand Down

0 comments on commit f1d2259

Please sign in to comment.