GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Prevent having two different unpacking methods by cyberdelia · Pull Request #548 · msgpack/msgpack-java

Prevent having two different unpacking methods #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
xerial merged 2 commits into msgpack:develop from cyberdelia:no-map-land
May 11, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

Prevent having two different unpacking methods #548

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
b7e7806
Prevent having two different unpacking methods
cyberdelia May 11, 2021
f48faa0
Fix loop
cyberdelia May 11, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

23 changes: 10 additions & 13 deletions 23 msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.msgpack.core.Preconditions.checkNotNull;

Expand Down Expand Up @@ -690,22 +686,23 @@ public Variable unpackValue(Variable var)
}
case ARRAY: {
int size = unpackArrayHeader();
List<Value> list = new ArrayList<Value>(size);
Value[] kvs = new Value[size];
for (int i = 0; i < size; i++) {
list.add(unpackValue());
kvs[i] = unpackValue();
}
var.setArrayValue(list);
var.setArrayValue(kvs);
return var;
}
case MAP: {
int size = unpackMapHeader();
Map<Value, Value> map = new HashMap<Value, Value>();
for (int i = 0; i < size; i++) {
Value k = unpackValue();
Value v = unpackValue();
map.put(k, v);
Value[] kvs = new Value[size * 2];
for (int i = 0; i < size * 2; ) {
kvs[i] = unpackValue();
i++;
kvs[i] = unpackValue();
i++;
Comment thread
cyberdelia marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}
var.setMapValue(map);
var.setMapValue(kvs);
return var;
}
case EXTENSION: {
Expand Down
88 changes: 49 additions & 39 deletions 88 msgpack-core/src/main/java/org/msgpack/value/Variable.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -798,6 +799,14 @@ public void writeTo(MessagePacker pk)
//

public Variable setArrayValue(List<Value> v)
{
this.type = Type.LIST;
this.accessor = arrayAccessor;
this.objectValue = v.toArray();
Comment thread
xerial marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

return this;
}

public Variable setArrayValue(Value[] v)
{
this.type = Type.LIST;
this.accessor = arrayAccessor;
Expand All @@ -824,29 +833,29 @@ public ArrayValue asArrayValue()
@Override
public ImmutableArrayValue immutableValue()
{
return ValueFactory.newArray(list());
return ValueFactory.newArray(array());
}

@Override
public int size()
{
return list().size();
return array().length;
}

@Override
public Value get(int index)
{
return list().get(index);
return array()[index];
}

@Override
public Value getOrNilValue(int index)
{
List<Value> l = list();
if (l.size() < index && index >= 0) {
Value[] a = array();
if (a.length < index && index >= 0) {
return ValueFactory.newNil();
}
return l.get(index);
return a[index];
}

@Override
Expand All @@ -856,21 +865,21 @@ public Iterator<Value> iterator()
}

@Override
@SuppressWarnings("unchecked")
public List<Value> list()
{
return (List<Value>) objectValue;
return Arrays.asList(array());
}

public Value[] array()
{
return (Value[]) objectValue;
}

@Override
public void writeTo(MessagePacker pk)
throws IOException
{
List<Value> l = list();
pk.packArrayHeader(l.size());
for (Value e : l) {
e.writeTo(pk);
}
immutableValue().writeTo(pk);
}
}

Expand All @@ -882,7 +891,25 @@ public Variable setMapValue(Map<Value, Value> v)
{
this.type = Type.MAP;
this.accessor = mapAccessor;
this.objectValue = v;
Value[] kvs = new Value[v.size() * 2];
Iterator<Map.Entry<Value, Value>> ite = v.entrySet().iterator();
int i = 0;
while (ite.hasNext()) {
Map.Entry<Value, Value> pair = ite.next();
kvs[i] = pair.getKey();
i++;
kvs[i] = pair.getValue();
i++;
}
this.objectValue = kvs;
return this;
}

public Variable setMapValue(Value[] kvs)
{
this.type = Type.MAP;
this.accessor = mapAccessor;
this.objectValue = kvs;
return this;
}

Expand All @@ -905,66 +932,49 @@ public MapValue asMapValue()
@Override
public ImmutableMapValue immutableValue()
{
return ValueFactory.newMap(map());
return ValueFactory.newMap(getKeyValueArray());
}

@Override
public int size()
{
return map().size();
return getKeyValueArray().length / 2;
}

@Override
public Set<Value> keySet()
{
return map().keySet();
return immutableValue().keySet();
}

@Override
public Set<Map.Entry<Value, Value>> entrySet()
{
return map().entrySet();
return immutableValue().entrySet();
}

@Override
public Collection<Value> values()
{
return map().values();
return immutableValue().values();
}

@Override
public Value[] getKeyValueArray()
{
Map<Value, Value> v = map();
Value[] kvs = new Value[v.size() * 2];
Iterator<Map.Entry<Value, Value>> ite = v.entrySet().iterator();
int i = 0;
while (ite.hasNext()) {
Map.Entry<Value, Value> pair = ite.next();
kvs[i] = pair.getKey();
i++;
kvs[i] = pair.getValue();
i++;
}
return kvs;
return (Value[]) objectValue;
}

@SuppressWarnings("unchecked")
public Map<Value, Value> map()
{
return (Map<Value, Value>) objectValue;
return immutableValue().map();
}

@Override
public void writeTo(MessagePacker pk)
throws IOException
{
Map<Value, Value> m = map();
pk.packArrayHeader(m.size());
for (Map.Entry<Value, Value> pair : m.entrySet()) {
pair.getKey().writeTo(pk);
pair.getValue().writeTo(pk);
}
immutableValue().writeTo(pk);
}
}

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.